import { DBListItem, DBListGetResultDB } from './model';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  DelSOURCE = '/admin/tabledefine/del',
  META_PAGE = '/admin/tabledefine/page',
  META_MODEL = '/admin/tabledefine/export',
  META_MENU = '/admin/tabledefine',
  META_UPDATE_MENU = '/admin/tabledefine/update',
  META_ADD_MENU = '/admin/tabledefine/add',
  META_GET_SQL = '/admin/tabledefine/getSql',
  META_EXECUTE_SQL = '/admin/tabledefine/executeSql',
  META_SAVE_SQL = '/admin/tabledefine/exportSql',
  // /tabledefine/exportSql/{tableId}
}

export const delMetaApi = (id: string) => {
  defHttp.post<any>({ url: Api.DelSOURCE + '/' + id });
};

export const getMetaPageApi = (params?: DBListItem) =>
  defHttp.get<DBListGetResultDB>({ url: Api.META_PAGE, params });

export const getMetaModelInfoApi = (params?: any) => {
  return defHttp.get<any>(
    { url: Api.META_MODEL, responseType: 'arraybuffer', params },
    { isTransformResponse: false },
  );
};

export const getMetaSqlApi = (tableId: number | string) =>
  defHttp.get<any>({ url: Api.META_GET_SQL + '/' + tableId });
export const getMetaSaveSqlApi = (tableId: number | string) =>
  defHttp.get<any>({ url: Api.META_SAVE_SQL + '/' + tableId });
export const getMetaMenuItemApi = (tableId: number) =>
  defHttp.get<any>({ url: Api.META_MENU + '/' + tableId });

export const updateMetaMenuApi = (params?: any) =>
  defHttp.post<any>({ url: Api.META_UPDATE_MENU, params });

export const addMetaMenuApi = (params?: any) =>
  defHttp.post<any>({ url: Api.META_ADD_MENU, params });

export const getMetaExecuteSqlApi = (data?: Indexable) => {
  console.log(
    '%cparams===>199： ',
    'background: rgb(23, 197, 237,.6); color: #ff5023; font-size:18px;font-weight:700',
    data,
  );
  return defHttp.post<any>({ url: Api.META_EXECUTE_SQL, data });
};
